import random

class Food:
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.position = self.random_position()
        self.color = self.random_color()

    def random_position(self):
        game_area_width = int(self.width * 0.8)  # 左侧80%的游戏区域宽度
        return [random.randrange(0, game_area_width, 20), random.randrange(0, self.height, 20)]

    def random_color(self):
        return (random.randint(100, 255), random.randint(100, 255), random.randint(100, 255))  # 生成随机颜色

    def reset(self, snake_body, ai_snake_body):
        while True:
            self.position = self.random_position()
            self.color = self.random_color()
            if self.position not in snake_body and self.position not in ai_snake_body:
                break